package com.moive.news.tqnewsapplication.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.moive.news.tqnewsapplication.R;
import com.moive.news.tqnewsapplication.base.Adapter.BaseListAdapter;
import com.moive.news.tqnewsapplication.entity.NewsHistInfo;
import com.moive.news.tqnewsapplication.entity.NewsInfo;
import com.moive.news.tqnewsapplication.utils.DateUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;

/**
 * Created by Administrator on 2017/12/25.
 */

public class NewsHisAdapter extends BaseListAdapter<NewsInfo.RowsBean> {
    private Context context;

    public NewsHisAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected View getItemView(int position, View convertView, ViewGroup parent, List<NewsInfo.RowsBean> item) {
        ViewHoder viewHoder = null;
        if (viewHoder == null) {
            viewHoder = new ViewHoder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_newshis, null);
            viewHoder.newshis_img = convertView.findViewById(R.id.newshis_img);
            viewHoder.newshis_commint = convertView.findViewById(R.id.newshis_commint);
            viewHoder.newshis_from = convertView.findViewById(R.id.newshis_from);
            viewHoder.newshis_ispass = convertView.findViewById(R.id.newshis_ispass);
            viewHoder.newshis_time = convertView.findViewById(R.id.newshis_time);
            convertView.setTag(this);
        } else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        Glide.with(context)
                .load(item.get(position).getUserHeadImg())
                .centerCrop()
                .dontAnimate()
                .placeholder(R.drawable.icon)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(viewHoder.newshis_img);
        try {
            if (!TextUtils.isEmpty(item.get(position).getTitle())) {
                String comment = URLDecoder.decode(item.get(position).getTitle(), "utf-8");
                viewHoder.newshis_commint.setText(comment);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        viewHoder.newshis_from.setText(item.get(position).getCategory());
        if (item.get(position).getStatus() == 0) {
            viewHoder.newshis_ispass.setText("未审核");
        } else if (item.get(position).getStatus() == 1) {
            viewHoder.newshis_ispass.setText("已通过");
        } else {
            viewHoder.newshis_ispass.setText("未通过");
        }
        String newtime = DateUtil.getDescriptionTimeFromTimestamp(item.get(position).getTime());
        viewHoder.newshis_time.setText(newtime);
//        viewHoder.newshis_ispass
        return convertView;
    }

    class ViewHoder {
        ImageView newshis_img;
        TextView newshis_commint, newshis_from, newshis_ispass, newshis_time;
    }
}
